package tests;

import static org.junit.Assert.assertEquals;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import org.joda.time.LocalDate;
import org.junit.Test;

import entity.general.MinTime;
import entity.main.Objective;
import entity.main.Task;
import entity.main.Task.TaskType;

public class SerializeTaskTest {

	@Test
	public void testSerializingTask() throws Exception {
		Task task = new Task("Name", TaskType.GOAL, new Objective("Test"), new LocalDate(),
				"Description", new MinTime(10, 10));
		task.addTimeSpent(new MinTime(1, 30));

		OutputStream outfile = new FileOutputStream("TaskTest.ser");
		OutputStream outbuffer = new BufferedOutputStream(outfile);
		ObjectOutput output = new ObjectOutputStream(outbuffer);
		output.writeObject(task);
		output.close();

		InputStream infile = new FileInputStream("TaskTest.ser");
		InputStream buffer = new BufferedInputStream(infile);
		ObjectInput input = new ObjectInputStream(buffer);

		Task task2 = (Task) input.readObject();

		assertEquals(task, task2);

	}

}
